﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace HealthHelper
{
    public partial class FrameForm : Form
    {

        [DllImport("user32.dll")]
        public static extern bool ReleaseCapture();

        [DllImport("user32.dll")]
        public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);

        private const int VM_NCLBUTTONDOWN = 0XA1;//定义鼠标左键按下
        private const int HTCAPTION = 2;
        public FrameForm()
        {
            InitializeComponent();
            this.Load += FrameForm_Load;
        }

        private void FrameForm_Load(object sender, EventArgs e)
        {
            this.Paint += Frame_Paint;
        }

        private Color frameColor = Color.FromArgb(98, 91, 90);
        public Color FrameColor { get { return frameColor; } set { frameColor = value; } }
        public void Frame_Paint(object sender, PaintEventArgs e)
        {
            System.Windows.Forms.Control control = sender as System.Windows.Forms.Control;
            if (control != null)
                ControlPaint.DrawBorder(e.Graphics, control.ClientRectangle,
                                    FrameColor, 1, ButtonBorderStyle.Solid,
                                    FrameColor, 1, ButtonBorderStyle.Solid,
                                    FrameColor, 1, ButtonBorderStyle.Solid,
                                    FrameColor, 1, ButtonBorderStyle.Solid);
        }

        private void FrameForm_MouseDown(object sender, MouseEventArgs e)
        {

            //为当前应用程序释放鼠标捕获
            ReleaseCapture();
            //发送消息 让系统误以为在标题栏上按下鼠标
            SendMessage((IntPtr)this.Handle, VM_NCLBUTTONDOWN, HTCAPTION, 0);
        }
    }
}
